﻿#pragma once


#include <QDialog>
#include <QPushButton>
#include "QListView"
#include "QStringListModel"
#include "QFileDialog"
#include "QMessageBox"
#include "QApplication"
#include "QVBoxLayout"
#include <QDesktopWidget>
#include <QLibrary>
#include <QApplication>
#include <QLabel>
#include <QComboBox>
#include "QListView"
#include "QStringListModel"
#include "QLineEdit"
#include "QSpinBox"
#include <QSettings>

#include "commonfunction.h"

#include "halcon_opencv.h"

using namespace std;

#include "qt_graphics_view_image.h"
#include "qt_graphics_shape_rectangle.h"





//#include <fstream>
//#include "nlohmann/json.hpp"
//using json = nlohmann::json;
//QSettings* m_qsettings;

class Measure1D :public QDialog
{
public:
    QSettings* m_qsettings;
    Mat m_image ,m_image_show;
    QString m_section   = "";

    MyQGraphicsView* m_view ;



//    QLabel* m_qlabel_row1;
//    QSpinBox* m_qspinbox_row1;

//    QLabel* m_qlabel_row2;
//    QSpinBox* m_qspinbox_row2;

//    QLabel* m_qlabel_column1;
//    QSpinBox* m_qspinbox_column1;

//    QLabel* m_qlabel_column2_offset;
//    QSpinBox* m_qspinbox_column2_offset;

//    QLabel* m_qlabel_roi_width;
//    QSpinBox* m_qspinbox_roi_width;

    QLabel* m_qlabel_threshold;
    QSpinBox* m_qspinbox_threshold;

    QComboBox* m_qcombox_transition;

    QLabel* m_qlabel_number;
    QSpinBox* m_qspinbox_number;

    QLabel * m_qlabel_range;
    QSpinBox * m_qspinbox_range;

    QLabel* m_qlabel_standard_short;
    QSpinBox* m_qspinbox_standard_short;
    int m_standard_short=0;

    QLabel* m_qlabel_standard_long;
    QSpinBox* m_qspinbox_standard_long;
    int m_standard_long=10000;

    QPushButton* m_pushbutton_detection;
    QPushButton* m_pushbutton_save_parameter;
    QPushButton* m_pushbutton_return;

    QLabel* m_qlabel_message;

    int m_result;

    HDevProcedure* m_proc_detection;
    HDevProcedureCall* m_call_detection;

    HTuple RowEdgeFirstShort, ColumnEdgeFirstShort, RowEdgeSecondShort, ColumnEdgeSecondShort, DistanceShort, RowEdgeFirstLong, ColumnEdgeFirstLong, RowEdgeSecondLong, ColumnEdgeSecondLong, DistanceLong;

    int m_y1_short,m_x1_short,m_y2_short,m_x2_short,m_distance_short;
    int m_y1_long,m_x1_long,m_y2_long,m_x2_long,m_distance_long;


    HObject image_in;
    int Row1, Column1, Row2, Column2;
    int RoiWidth,Threshold,Transition,Number,Range;
    

public:
    explicit Measure1D(QDialog *parent = nullptr, QSettings* qsettings = nullptr,QString section="") ;
    ~Measure1D() ;
    virtual void detectionImage();
    virtual bool detection( HObject image_in, QString& message);
    virtual void draw( Mat image_in,Mat& image_out);
    virtual void loadParameter();
    virtual void saveParameter();
    virtual bool showDialog();
    void getRect(int x,int y,int width,int height);
};
#pragma execution_character_set("utf-8")
